package com.qxp.simplerpc.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @author qianxiaopeng
 */
@SuppressWarnings("unchecked")
public class JdkProxy extends CommonProxy implements InvocationHandler {
    private String className;
    private Class<?> interfaceI;
    private String beanName;
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        return this.connect(interfaceI,method,args,className, beanName);
    }
    /**
     * instance a new instance
     * @param className
     * @param <T>
     * @return
     */
    @Override
    public <T> T getProxy(Class<?> cls, String className,String beanName) {
        this.className = className;
        this.interfaceI = cls;
        this.beanName = beanName;
        return (T) Proxy.newProxyInstance(cls.getClassLoader(), new Class[]{cls}, this);
    }
}
